#!/bin/bash

if test -x "`which dig 2>/dev/null`"; then
  dig @208.67.222.220 myip.opendns.com +short | tee /tmp/myip.log
elif test -x "`which drill 2>/dev/null`"; then
  drill @208.67.222.220 myip.opendns.com | grep '^myip.opendns.com'| cut -f 5
else
  exit 1
fi

#also works:
#dig @ns1.google.com -t txt o-o.myaddr.l.google.com +short
# I guess -4 is implied FIXME: must check when/if it uses -6 or -4  say if both are available.
#dig -4 @ns1.google.com -t txt o-o.myaddr.l.google.com +short
#dig -6 @ns1.google.com -t txt o-o.myaddr.l.google.com +short

# as per src: https://serverfault.com/questions/89114/finding-the-public-ip-address-in-a-shell-script

